﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PO_2011;

namespace WindowsFormsApplication1
{
    public partial class BinarizationAlgorythms : Form
    {
        private Pnm p;
        public Form1 refToMainWindow;
        public bool TypWygladzania;
        private int algorytmTyp = 0, MacierzWidthIHight = 7; double K = -0.5, KWR = 0.5;
        public Bitmap oryginalB;

        public BinarizationAlgorythms(Pnm objectPnm)
        {
            InitializeComponent();
            p = objectPnm;

            pictureBox1.Size = new System.Drawing.Size(p.GetWidth, p.GetHeight);
            this.ClientSize = new System.Drawing.Size(p.GetWidth + 350, p.GetHeight + 150);
            pictureBox1.Image = p.getBitmap(); 
            comboBox1.Text = "7x7"; comboBox2.Text = "Niblack"; oryginalB = new Bitmap(p.getBitmap());
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string s = comboBox1.SelectedItem.ToString();
            if (s == "3x3")
            {
                MacierzWidthIHight = 3;
            }
            else
                if (s == "7x7")
                {
                    MacierzWidthIHight = 7;
                }
                else
                    if (s == "13x13")
                    {
                        MacierzWidthIHight = 13;
                    }
                else
                {
                    MacierzWidthIHight = 5;
                }
        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            string s = comboBox2.SelectedItem.ToString();
            if (s == "Niblack")
            {
                algorytmTyp = 0;
            }
            else if (s == "Bernsen")
            {
                algorytmTyp = 1;
            }
            else if (s == "WhiteRohrer")
            {
                algorytmTyp = 2;
            }

        }

        private void button1_Click(object sender, EventArgs e)
        {
            p.bitmapOryginal = oryginalB;
            pictureBox1.Image = p.BinarizationAlgorythms(MacierzWidthIHight, algorytmTyp,K,KWR);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.refToMainWindow.pictureBox1.Image = p.BitmapFiltr;
            p.bitmap = p.BitmapFiltr;
            this.Close();
        }

        private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
        {
            string s = comboBox1.SelectedItem.ToString();
            if (s == "-0.5")
            {
                K = -0.5;
            }
            else
                if (s == "-1")
                {
                    K = -1;
                }
                else{
                     if (s == "-2")
                    {
                        K = -2;
                    }}
                    
        }

        private void comboBox4_SelectedIndexChanged(object sender, EventArgs e)
        {
            string s = comboBox1.SelectedItem.ToString();
            if (s == "1")
            {
                KWR = 1;
            }
            else
                if (s == "1.5")
                {
                    KWR = 1.5;
                }
                else
                {
                    if (s == "2")
                    {
                        KWR = 2;
                    }
                }
        }
    }
}
